package routers

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"personal-blog/controllers"
)

func SetupRouter() *gin.Engine {
	r := gin.Default()
	v1 := r.Group("/blog/v1")
	v1.GET("/ping", func(c *gin.Context) {
		c.String(http.StatusOK, "pang")
	})
	v1.POST("/signup", controllers.SignUpHandler)
	v1.POST("/login", controllers.LoginHandler)
	v1.GET("/refresh_token", controllers.RefreshTokenHandler)
	v1.GET("/user_list", controllers.UserList)
	v1.GET("/userblog/:username", controllers.UserDetailHandler)
	v1.GET("/blog_detail/:blogid", controllers.BlogDetailHandler)
	v1.POST("/blog_detail/:blogid", controllers.UpdateBlogDetailHandler)
	v1.POST("/delete/:blogid", controllers.DeleteBlogDetailHandler)
	v1.GET("/blog_all", controllers.BlogAllHandler)

	v1.Use(controllers.JWTAuthMiddleware())
	{
		v1.POST("/createblog", controllers.CreateBlog)
	}

	r.NoRoute(func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{
			"msg": "404",
		})
	})
	return r
}
